package com.yiwei.zhh.view;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;

class PaintUtil {

    public static Paint createTextPaint(Context context, float textSize, int textStyle, int typeface, String typefacePath) {
        Paint paint = new Paint();
        paint.setTextSize(textSize);
        paint.setColor(0xff000000);
        Typeface tf = null;

        switch (typeface) {
        case -1:
            try {
//                tf = Typeface.createFromAsset(context.getAssets(), typefacePath);
            } catch (Exception e) {
            }
            break;
        case 1:
            tf = Typeface.SANS_SERIF;
            break;
        case 2:
            tf = Typeface.SERIF;
            break;
        case 3:
            tf = Typeface.MONOSPACE;
            break;
        }

        if (textStyle > 0) {
            if (tf == null) {
                tf = Typeface.defaultFromStyle(textStyle);
            } else {
                tf = Typeface.create(tf, textStyle);
            }

            paint.setTypeface(tf);
            // now compute what (if any) algorithmic styling is needed
            int typefaceStyle = tf != null ? tf.getStyle() : 0;
            int need = textStyle & ~typefaceStyle;
            paint.setFakeBoldText((need & Typeface.BOLD) != 0);
            paint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
        } else {
            paint.setFakeBoldText(false);
            paint.setTextSkewX(0);
            paint.setTypeface(tf);
        }
        return paint;
    }
}